<template>
  <div class="list-item">
    <div class="list-item-left" @click="jumpToDetails()">
      <van-image fit="cover" :src="baseURL + data.poster" />
    </div>
    <div class="list-item-center" @click="jumpToDetails()">
      <div class="title">{{ data.name }}</div>
      <div>类型：{{ data.type }}</div>
      <div class="rate">
        <van-rate
          v-model="data.starScore"
          :size="rateSize"
          color="#4B9E67"
          void-color="#79BD90"
          readonly
          allow-half
          ref="rate"
        />
        <div class="rate-text">{{ data.score }}分</div>
      </div>
      <div>导演：{{ data.director }}</div>
      <div class="actor">演员：{{ data.actor }}</div>
    </div>
    <div class="list-item-right">
      <button type="button" @click="buy">购票</button>
    </div>
  </div>
</template>

<script>
export default {
  props: ["data"],
  data() {
    return {
      rateSize: "3.3vw",
      baseURL: "http://10.36.4.254:8080/",
    };
  },
  methods: {
    jumpToDetails() {
      // 这个id是HomeView传过来的，是该电影的唯一标识
      this.$router.push("/MovieDetails/" + this.data.id);
    },
    buy() {
      console.log("这个电影id为" + this.data.id + ",你点了购票按钮...");
      // this.$router.push("/cinemachoose/" + this.data.id);
      this.$router.push({
        path:"/cinemachoose",
        query:{
          movieId:this.data.id,
        }
      });
    },
  },
  mounted() {
    window.addEventListener("resize", () => {
      // 根据视窗宽度 用于改变评分星星的大小 相当于js里面的响应式
      if (document.documentElement.clientWidth > 600) {
        console.log(768);
        this.rateSize = "20px";
      } else this.rateSize = "3.3vw";
    });
  },
};
</script>
 
<style lang="scss" scoped>
.list-item {
  display: flex;
  width: 100%;
  height: 28vw;
  background-color: #fff;
  border-radius: 0.3rem;
  &:not(:last-child) {
    margin-bottom: 0.5rem;
  }
  > .list-item-left {
    width: 23vw;
    // background-color: skyblue;
    overflow: hidden;
    border-radius: 0.3rem;
  }
  > .list-item-center {
    > .title {
      color: #1f1f1f;
      font-weight: 700;
    }

    display: flex;
    flex-flow: column nowrap;
    justify-content: space-evenly;
    width: 50vw;
    color: #858585;
    // background-color: rgb(255, 203, 136);
    padding: 0 0.5rem;
    //!!这里是从未遇见过的feature!! 解决 flex white-space: nowrap,撑大盒子的问题
    min-width: 0;
  }
  > .list-item-right {
    // background-color: aqua;
    color: #fff;
    width: 25vw;
    display: flex;
    justify-content: center;
    align-items: center;
    > button {
      border: none;
      height: 1.7rem;
      line-height: 1.7rem;
      padding: 0 0.7rem;
      background-color: #79bd90;
      border-radius: 1.7rem;
    }
  }
}
.actor {
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
}
.rate {
  display: flex;
  align-items: center;
  > .rate-text {
    margin-left: 1.4vw;
    color: #79bd90;
  }
}
@media (min-width: 600px) {
  .rate > .rate-text {
    margin-left: 8.4px;
  }
}
@media (min-width: 768px) {
  .list-item > .list-item-left {
    width: 109px;
  }
  .list-item > .list-item-center {
    width: 371.4px;
  }
  .list-item > .list-item-right {
    width: 177.7px;
  }
}
</style>